<template>
    <div class="body-bj" ref="homePage">
        <div class="header"></div>
		<div class="centent">
			<div class="login-box">
                <div class="login-ww">
                    <div class="login-input">
                        <div class="login-zh">
                            <span class="login-title">登录</span>
                            <input type="" name="" id="" v-model="parmes.username" placeholder="手机号/邮箱/用户名" />
                            <input type="password" name="" id="" v-model="parmes.password" placeholder="请输入密码" />
                            <div class="checkbox-el">
                                <el-checkbox v-model="checked">记住登录名</el-checkbox>
                            </div>
                            <span class="login-button" @click="studentsLogin()">登陆</span>
                        </div>
                    </div>
                </div>
			</div>
		</div>
    </div>
</template>
<script>
import apiHttp from '../api/index.js'
export default {
    data(){
        return{
            clientHeight:'',
            activeName: 'first',
            checked:'',
            parmes:{
                username:localStorage.getItem('username') ? localStorage.getItem('username') : '',
                password:'',
                type:3
            }
        }
    },
    mounted(){
        this.clientHeight = `${document.documentElement.clientHeight}`
        window.onresize = function temp(){
            this.clientHeight = `${document.documentElement.clientHeight}`
        }
        if(localStorage.getItem('isKeep') == 'true'){
            this.checked = true
        }else{
            this.checked = false
            localStorage.removeItem("username")
        }
        // 获取vux中多的数据
        // this.checked = this.$store.state.login.isKeep
    },
    watch:{
        clientHeight(){
            this.changeFixed(this.clientHeight)
        },
        // 调取vux里面的方法
        checked(){
            this.$store.commit('IsKeep')
            localStorage.setItem("isKeep",this.checked)
        },
        parmesVal(newVal,oldVal){
            if(this.checked){
                localStorage.setItem("username",this.parmes.username)
            }else{
                localStorage.removeItem("username")
            }
        }
    },
    computed:{
        parmesVal(){
            return this.parmes.username
        }
    },
    methods:{
        changeFixed(clientHeight){
            let w = clientHeight
            this.$refs.homePage.style.height = `${w}px`
        },
        // 考生登录
        studentsLogin(){
            apiHttp.apiIndex.login(this.parmes).then(resp=>{
                if(resp.code == 0){
                    localStorage.setItem('adminToken',resp.data)
                    localStorage.setItem("username",this.parmes.username)
                    this.$router.push({
                        path:'/nav/home'
                    })
                }else{
                    this.$message.error(resp.message)
                }
            })
        }
    }
}
</script>

<style scoped>
.login-title{
    display: block;
    color: #000;
    font-size: 26px;
    font-weight: bold;
}
.body-bj{
    width: 100%;
    height: 100%;
    background: url(../../static/img/content.jpg) no-repeat center;
    background-size: cover;
    overflow: hidden;
    position: relative;
}
.header{
    background: url(../../static/img/header.jpg) no-repeat center #5d2805;
    width: 100%;
    height: 119px;
}
.centent{
    width: 100%;
    height: 100%;
}
.login-box{
    width: 365px;
    height: 365px;
    position: fixed;
    top:50%;
    left: 50%;
    margin-left: -182px;
    margin-top: -200px;
    background: url(../../static/img/kuang.png) no-repeat center;
}
.login-ww{
    margin:10px;
    width: 345px;
    height: 345px;
    background-color: #f7f5ec;
    overflow: hidden;
}
.login-input{
    width: 290px;
    height: 290px;
    background-color: #fff;
    margin: 27px auto;
    box-shadow: 0 0 10px #e2dacd;
}
.login-zh{
    width: 250px;
    height: 250px;
    padding: 20px;
}
.login-input input{
    height: 38px;
    border: solid 1px #bfbfbf;
    width: 90%;
    font-size: 14px;
    color: #000;
    line-height: 38px;
    outline:none;
    padding-left: 5%;
    margin-top: 10px;
    border-radius: 3px;
}
.checkbox-el{
    height: 20px;
    width: 94%;
    margin: 10px auto 0;
}
.checkbox-el span{
    font-size: 12px;
    float: right;
    cursor: pointer;
}
.checkbox-el span:nth-child(2){
    padding-left: 10px;
}
.login-button{
    background-color: #5d2805;
    height: 40px;
    width: 100%;
    margin-top: 20px;
    line-height: 40px;
    color: #fff;
    font-size: 16px;
    display: block;
    text-align: center;
    border-radius: 5px;
    cursor: pointer;
}
.biaoti{
    width: 100%;
    font-size: 34px;
    font-weight: bold;
    text-align: center;
    padding-top: 30px;
    display: block;
}
</style>
